package com.easywan.util;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import net.sf.json.JSONObject;

public class Utils {
	
	/**
	 * 判断list是否为空
	 * @author T
	 * @param usersList
	 * @return
	 */
	public static <T> Boolean listIsEmpty(List<T> usersList) {
		if(usersList == null){
			return true;
		}
		if(usersList.size() <= 0){
			return true;
		}
		return false;
	}
	public static Boolean stringIsEmpty(String string){
		if(string  == null){
			return true;
		}else if(string.trim().length() <= 0){
			return true;
		}else{
			return false;
		}
	}
	public static Boolean isEmail(String name) {
		if(name.indexOf("@") > 1){
			return true;
		}
		return false;
	}
	public static Date getNowDate() {
		return new Date(System.currentTimeMillis());
	}
	public static <T> T listGetOne(List<T> selectSelective) {
		if(listIsEmpty(selectSelective)){
			return null;
		}else{
			return selectSelective.get(0);
		}
		
	}
	/*public static BaseModel loadFiled(HttpServletRequest request, Class<?> cls) throws InstantiationException, IllegalAccessException, SecurityException {
		Object obj = cls.newInstance();
		Enumeration<String> names = request.getParameterNames();
		while(names.hasMoreElements()){
			String name = names.nextElement();
			System.out.println(name);
			try{
				Method m = cls.getMethod("set"+StringsUtils.firestToUpper(name),String.class);
				m.invoke(obj, request.getParameter(name));
			}catch(Exception e){
				Method m;
				try {
					m = cls.getMethod("set"+StringsUtils.firestToUpper(name),Boolean.class);
					m.invoke(obj, Boolean.valueOf(request.getParameter(name)));
				} catch (Exception e1) {
				}
				
			}
		}
		System.out.println(obj);
		return (BaseModel) obj;
	}*/
	/*public static void sendSuccessMsg(HttpServletResponse response) {
		sendMsg(response, "1");
	}*/
	public static <T>  List<T> listNotRe(List<T> list) {
            List<T> listTemp = new ArrayList<T>();  
            for(int i=0;i<list.size();i++){  
                if(!listTemp.contains(list.get(i))){  
                    listTemp.add(list.get(i));  
                }  
            }  
            return listTemp;  
	}

	
	
}
